//
//    LunokWatch, a open source smartwatch software
//    Copyright (C) 2022,2023  Jordi Rubió <jordi@binarycell.org>
//    This file is part of LunokWatch.
//
// LunokWatch is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software 
// Foundation, either version 3 of the License, or (at your option) any later 
// version.
//
// LunokWatch is distributed in the hope that it will be useful, but WITHOUT 
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
// details.
//
// You should have received a copy of the GNU General Public License along with 
// LunokWatch. If not, see <https://www.gnu.org/licenses/>. 
//

#ifndef __LUNOKIOT__APPLICATION__OTAUPDATE__
#define __LUNOKIOT__APPLICATION__OTAUPDATE__

#include "../UI/AppTemplate.hpp"
#include "../UI/widgets/ButtonImageXBMWidget.hpp"
#include "../UI/widgets/GaugeWidget.hpp"
#include "../UI/widgets/GraphWidget.hpp"
#include <esp_https_ota.h>

class OTAUpdateApplication : public TemplateApplication {
    private:
        uint32_t backgroundColor=ThCol(background);
        unsigned long nextRefresh=0;
        //unsigned long nextProgressbarRefresh=0;
        ButtonImageXBMWidget *updateBtn=nullptr;
        GaugeWidget * progressBar=nullptr;
        //GraphWidget * OTADownloadSpeed=nullptr;
        int imageSize=0;
        int imageDownloaded=0;
        char percentAsString[5] = "0%";
        char *bufferForText = nullptr;

    public:
        const char *AppName() override { return "OTA updater"; };
        OTAUpdateApplication();
        ~OTAUpdateApplication();
        bool Tick();
};

#endif
